﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using PccCommonForC;

public partial class Manager_Menu_MenuD : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

        if (!IsPostBack)
        {
            if ((Request.QueryString["AutID"] != "" && Request.QueryString["AutID"] != null) || Request.QueryString["index"] == "1")
            {
                txtEmail.Attributes.Add("onkeydown", "if(event.which || event.keyCode){if ((event.which == 13) || (event.keyCode == 13)) {document.getElementById('" + btnSearch.ClientID + "').click();return false;}} else {return true}; ");
                txtLogin.Attributes.Add("onkeydown", "if(event.which || event.keyCode){if ((event.which == 13) || (event.keyCode == 13)) {document.getElementById('" + btnSearch.ClientID + "').click();return false;}} else {return true}; ");
                txtName.Attributes.Add("onkeydown", "if(event.which || event.keyCode){if ((event.which == 13) || (event.keyCode == 13)) {document.getElementById('" + btnSearch.ClientID + "').click();return false;}} else {return true}; ");

                MultiView1.ActiveViewIndex = 1;
                BindDataAuthority();
                btnAddGroupMn.Visible = false;
            }
            else
            {
                MultiView1.ActiveViewIndex = 0;
                btnGrpUser.Visible = false;
                BindAuthorityList();
                BinDataUser();
            }

        }
    }
    private void BindDataAuthority()
    {
        PccMsg msg = new PccMsg();
        msg.CreateFirstNode("AutNm", txtQuyenHan.Text);

        clsWebShop cls = new clsWebShop();
        DataSet ds = null;
        ds = cls.Get_shr_AuthorityCondition(msg.GetXmlStr);
        grv_MasterAuthority.DataSource = ds;
        grv_MasterAuthority.DataBind();

    }
    private void BindAuthorityList()
    {
        clsWebShop cls = new clsWebShop();
        ListItem item = new ListItem();
        ddlChuDe.DataSource = cls.Get_shr_AuthorityNoneProc().Tables[0];
        ddlChuDe.DataTextField = "AutNm";
        ddlChuDe.DataValueField = "AutID";
        ddlChuDe.DataBind();
        item.Text = "-- Chọn quyền hạn --";
        item.Value = "0";
        ddlChuDe.Items.Insert(0, item);
    }

    private void BinDataUser()
    {
        PccMsg msg = new PccMsg();
        msg.CreateFirstNode("CusNm", txtName.Text.Trim());
        msg.CreateFirstNode("UserNm", txtLogin.Text.Trim());
        msg.CreateFirstNode("Email", txtEmail.Text.Trim());
        msg.CreateFirstNode("AutID", ddlChuDe.SelectedValue);
        msg.CreateFirstNode("UserID", "0");
        clsWebShop cls = new clsWebShop();
        DataSet ds = null;
        ds = cls.Get_shr_UserCondition(msg.GetXmlStr);
        grv_MasterUser.DataSource = ds;
        grv_MasterUser.DataBind();

    }
    protected void btnSearch_Click(object sender, EventArgs e)
    {
        BinDataUser();
    }

    protected void ddlChuDe_SelectedIndexChanged(object sender, EventArgs e)
    {
        BinDataUser();
    }
    protected void grv_MasterUser_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            e.Row.Attributes.Add("onmouseover", "this.className='cursorOverGrid'");
            if (e.Row.RowIndex % 2 == 0)
                e.Row.Attributes.Add("onmouseout", "this.className='gvRowStyle'");
            else
                e.Row.Attributes.Add("onmouseout", "this.className='gvAlternatingRowStyle'");

        }
    }

    protected void btnGrpUser_Click(object sender, EventArgs e)
    {
        btnGrpUser.Visible = false;
        //btnAddGroupMn.Visible = true;
        MultiView1.ActiveViewIndex = 0;
        BindAuthorityList();
        BinDataUser();
    }
    protected void btnAddGroupMn_Click(object sender, EventArgs e)
    {
        btnGrpUser.Visible = true;
        btnAddGroupMn.Visible = false;
        MultiView1.ActiveViewIndex = 1;
        BindDataAuthority();
        // BinData();


    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        BindDataAuthority();
    }
    protected void grv_MasterUser_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        grv_MasterUser.PageIndex = e.NewPageIndex;
        BinDataUser();
    }
    protected void grv_MasterAuthority_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        grv_MasterAuthority.PageIndex = e.NewPageIndex;
        BindDataAuthority();
    }
}
